"""
开放商户 - 商户结算规则修改相关模型
"""

from typing import Dict, Any
from jlpay.model.base import OrgBaseReq, BaseResponse
from jlpay.utils.annotation_utils import Encrypt


@Encrypt  # 标记整个类需要加密处理，对应Java代码中的@DataCrypto(encrypt = true)
class SettleRuleModifyRequest(OrgBaseReq):
    """商户结算规则修改请求"""
    
    API_URL = "/open/merch/access/settle-rule/modify"
    
    def __init__(self):
        """初始化商户结算规则修改请求"""
        super().__init__()
        self.apply_id = None  # 申请单id
        self.merch_no = None  # 商户号
        self.settle_mode = None  # 结算方式
        self.day_cut = None  # 营业周期，结算日切时间
        self.settle_session = None  # 结算场次
        self.account_change_flag = None  # 是否允许商户自主变更结算账户，0-否1-是
        self.postscript = None  # 结算附言
    
    def set_apply_id(self, apply_id):
        """
        设置申请单id
        
        Args:
            apply_id: 申请单id
            
        Returns:
            SettleRuleModifyRequest实例
        """
        self.apply_id = apply_id
        return self
    
    def set_merch_no(self, merch_no):
        """
        设置商户号
        
        Args:
            merch_no: 商户号
            
        Returns:
            SettleRuleModifyRequest实例
        """
        self.merch_no = merch_no
        return self
    
    def set_settle_mode(self, settle_mode):
        """
        设置结算方式
        
        Args:
            settle_mode: 结算方式
            
        Returns:
            SettleRuleModifyRequest实例
        """
        self.settle_mode = settle_mode
        return self
    
    def set_day_cut(self, day_cut):
        """
        设置营业周期，结算日切时间
        
        Args:
            day_cut: 营业周期，结算日切时间
            
        Returns:
            SettleRuleModifyRequest实例
        """
        self.day_cut = day_cut
        return self
    
    def set_settle_session(self, settle_session):
        """
        设置结算场次
        
        Args:
            settle_session: 结算场次
            
        Returns:
            SettleRuleModifyRequest实例
        """
        self.settle_session = settle_session
        return self
    
    def set_account_change_flag(self, account_change_flag):
        """
        设置是否允许商户自主变更结算账户
        
        Args:
            account_change_flag: 是否允许商户自主变更结算账户，0-否1-是
            
        Returns:
            SettleRuleModifyRequest实例
        """
        self.account_change_flag = account_change_flag
        return self
    
    def set_postscript(self, postscript):
        """
        设置结算附言
        
        Args:
            postscript: 结算附言
            
        Returns:
            SettleRuleModifyRequest实例
        """
        self.postscript = postscript
        return self
    
    def to_dict(self) -> Dict[str, Any]:
        """
        将请求对象转换为字典
        
        Returns:
            字典对象
        """
        data = super().to_dict()
        data['apply_id'] = self.apply_id
        data['merch_no'] = self.merch_no
        data['settle_mode'] = self.settle_mode
        data['day_cut'] = self.day_cut
        data['settle_session'] = self.settle_session
        data['account_change_flag'] = self.account_change_flag
        data['postscript'] = self.postscript
        return data


class SettleRuleModifyResponse(BaseResponse):
    """商户结算规则修改响应参数"""
    
    def __init__(self, response_dict=None):
        """
        初始化商户结算规则修改响应
        
        Args:
            response_dict: 响应字典
        """
        super().__init__(response_dict)
        self.merch_no = None  # 商户号
        self.apply_id = None  # 业务申请编号
        
        if response_dict:
            self.merch_no = response_dict.get('merch_no')
            self.apply_id = response_dict.get('apply_id')
    
    def to_dict(self) -> Dict[str, Any]:
        """
        将响应对象转换为字典
        
        Returns:
            字典对象
        """
        data = super().to_dict()
        data['merch_no'] = self.merch_no
        data['apply_id'] = self.apply_id
        return data 